<%= stylesheet_link_tag "components/_small_video" %>

<%= javascript_include_tag 'countUp.min' %>

<script type="text/javascript" charset="utf-8">
    var STBType = Authentication.CTCGetConfig("STBType"); // 机顶盒型号

    if (STBType === "EC6108V8") {
        setInterval(function () {
            window.focus();
        }, 500);
    }

    var counter;

    var resetCount = function () {
    };

    // 计算iframe的src, 华为中兴两平台有不同
    var changeMediaSrc = function (contentID) {
        var last, host, src;
        var epgDomain = Authentication.CTCGetConfig("EPGDomain");
        <% if cookies[:platform].include?('HUAWEI') %>
        last = epgDomain.indexOf("/", 10);
        host = epgDomain.substr(0, last);
        src = host + "/EPG/MediaService/SmallScreen.jsp?ContentID=" + contentID + "&Left=55&Top=145&Width=580&Height=320&CycleFlag=1&GetCntFlag=0";
        <% else %>
        last = epgDomain.lastIndexOf("/");
        host = epgDomain.substr(0, last);
        src = host + "/MediaService/SmallScreen?ContentID=" + contentID + "&Left=55&Top=145&Width=580&Height=320&CycleFlag=1&GetCntFlag=0";
        <% end %>
        $("iframe#one_frame").attr("src", src);
        setTimeout(function () {
            window.focus();
        }, 2000);
    };

    $(function () {
        var frame = root.getWidgetById("one_frame");

        // 点击即跳转
        frame.on("keydown", function (e) {
            e = e || window.event;
            var keyValue = e.which || e.keyCode;
            if (keyValue === 13) {
                Cookies.set('second_prev', Cookies.get('prev'))
                Cookies.set('prev', "<%= request.path %>" + "?song_id=" + e.target.con.dataset.song_id)
                window.location.href = e.target.con.dataset.href;
                return false;
            }
        });

        <% if cookies[:order_type] == 'free' %>
        // 首先声明实例, 调用resetCount()进行计数并跳转去实例
        counter = new CountUp("small-video-counter-number", 0, {
            startVal: 60,
            duration: 60,
            useEasing: false
        });

        // 重置定时器
        resetCount = function () {
            counter.reset();
            counter.start(function () {
                window.location.href = "<%= platform_order_path(original_fullpath: request.original_fullpath) %>";
            });
        };
        <% end %>
    });
</script>

<div class="small-video" fe-role="Switch">
  <% if cookies[:order_type] == 'free' %>
    <div class="small-video-counter">
      <div class="small-video-counter-text">
        免费试听<span id="small-video-counter-number"></span>秒
      </div>
    </div>
  <% end %>
  <iframe
    id="one_frame"
    data-href
    data-song_id
    src
    fe-role="Widget"
    width="580px"
    height="320px"
    class="one_frame"
    name="if_smallscreen"
    frameborder="no"
    scrolling="no"
  >
  </iframe>
</div>
